package com.sanqing.main;

import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class MyDocument extends PlainDocument {

    private final int maxLength;

    public MyDocument(int newMaxLength) {

        super();
        maxLength = newMaxLength;

    }

    public MyDocument() {

        this(10);
    }

    public void insertString(int offset, String str, javax.swing.text.AttributeSet a) throws BadLocationException {

        if (getLength() + str.length() <= maxLength) {
            try {
                super.insertString(offset, str, a);
            } catch (BadLocationException e) {
                e.printStackTrace();
            }
        }
    }
}